package cn.yeziji.file.converter;

import cn.yeziji.file.basic.FileProcess;
import cn.yeziji.file.vo.FileVO;
import cn.yeziji.forum.entity.ForumFileEntity;
import cn.yzj.entity.MinioFileEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 文件数据转换器
 *
 * @author gzkemays
 * @since 2022/5/12 16:54
 */
@Mapper
public interface FileConverter {
  FileConverter INSTANCE = Mappers.getMapper(FileConverter.class);

  /**
   * Minio 文件数据转 VO
   *
   * @param entity minio entity
   * @return vo
   */
  FileVO minioFileEntityConvertToFileVO(MinioFileEntity entity);

  /**
   * to list --> {@link #minioFileEntityConvertToFileVO(MinioFileEntity)}
   *
   * @param entities entity list
   * @return vos
   */
  List<FileVO> minioFileEntitiesConvertToFileVOS(List<MinioFileEntity> entities);

  /**
   * 论坛文件元对象转换为进度对象
   *
   * @param entity 元对象
   * @return 进度对象
   */
  @Mapping(target = "username", source = "source")
  @Mapping(target = "process", expression = "java(\"1\")")
  @Mapping(target = "createTime", dateFormat = "yyyy-MM-dd HH:mm:SS")
  @Mapping(
      target = "filename",
      expression = "java(cn.yzj.utils.DataUtils.substrAfterOfLastTag(entity.getScope(),\"/\"))")
  FileProcess forumFileEntityConvertToFileProcess(ForumFileEntity entity);

  /**
   * to link {@link #forumFileEntityConvertToFileProcess(ForumFileEntity)}
   *
   * @param entities entity list
   * @return file process list
   */
  List<FileProcess> forumFileEntitiesConvertToFilesProcess(List<ForumFileEntity> entities);
}
